package zkclient.dwj.cn;

import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.serialize.SerializableSerializer;

import java.util.List;

/**
 * Created by Administrator on 2017/11/13 0013.
 */
public class SubscribeChildChange {
    public static void main(String[] args) throws InterruptedException {
        ZkClient zc = new ZkClient("192.168.110.134:2181", 10000, 10000, new SerializableSerializer());
        System.out.println("connect ok");

        zc.subscribeChildChanges("/ding", new ZkChildListener());//监听节点的子节点变化
        Thread.sleep(Integer.MAX_VALUE);
    }

    private static class ZkChildListener implements IZkChildListener{

        public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
            System.out.println(parentPath);
            System.out.println(currentChilds.toString());
        }
    }
}
